package com.ruoyi.web.controller.production.pesticide;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.production.service.pesticide.IPesticideAmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.pesticide.PesticidePurchase;
import com.ruoyi.production.service.pesticide.IPesticidePurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农药购买信息Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/pesticidePurchase")
@Api(value = "农药购买",tags = "农药购买相关API")
public class PesticidePurchaseController extends BaseController
{
    @Autowired
    private IPesticidePurchaseService pesticidePurchaseService;
    @Autowired
    private IPesticideAmountService pesticideAmountService;

    /**
     * 查询农药购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:pesticidePurchase:list')")
    @GetMapping("/list")
    @ApiOperation("获取农药购买表信息")
    @ApiImplicitParam(name = "pesticidePurchase",value = "农药购买实体类",paramType = "body", dataType = "PesticidePurchase")
    public TableDataInfo list(PesticidePurchase pesticidePurchase)
    {
        startPage();
        List<PesticidePurchase> list = pesticidePurchaseService.selectPesticidePurchaseList(pesticidePurchase);
        return getDataTable(list);
    }

    /**
     * 导出农药购买信息列表
     */
    @PreAuthorize("@ss.hasPermi('production:pesticidePurchase:export')")
    @Log(title = "农药购买信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出农药购买表信息")
    @ApiImplicitParam(name = "pesticidePurchase",value = "农药购买实体类",paramType = "body", dataType = "PesticidePurchase")
    public AjaxResult export(PesticidePurchase pesticidePurchase)
    {
        List<PesticidePurchase> list = pesticidePurchaseService.selectPesticidePurchaseList(pesticidePurchase);
        ExcelUtil<PesticidePurchase> util = new ExcelUtil<PesticidePurchase>(PesticidePurchase.class);
        return util.exportExcel(list, "农药购买信息数据");
    }

    /**
     * 获取农药购买信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:pesticidePurchase:query')")
    @GetMapping(value = "/{pesticidePurchaseId}")
    @ApiOperation("获取农药购买表单个信息")
    @ApiImplicitParam(name = "pesticidePurchaseId",value = "农药购买实体类主键",paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("pesticidePurchaseId") Long pesticidePurchaseId)
    {
        return AjaxResult.success(pesticidePurchaseService.selectPesticidePurchaseById(pesticidePurchaseId));
    }

    /**
     * 新增农药购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:pesticidePurchase:add')")
    @Log(title = "农药购买信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增农药购买表信息")
    @ApiImplicitParam(name = "pesticidePurchase",value = "农药购买实体类",paramType = "body", dataType = "PesticidePurchase")
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody PesticidePurchase pesticidePurchase)
    {
        return toAjax(pesticidePurchaseService.insertPurchaseUpdateAmount(pesticidePurchase));
    }

    /**
     * 修改农药购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:pesticidePurchase:edit')")
    @Log(title = "农药购买信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改农药购买表信息")
    @ApiImplicitParam(name = "pesticidePurchase",value = "农药购买实体类",paramType = "body", dataType = "PesticidePurchase")
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody PesticidePurchase pesticidePurchase)
    {
        return toAjax(pesticidePurchaseService.updatePesticidePurchase(pesticidePurchase));
    }

    /**
     * 删除农药购买信息
     */
    @PreAuthorize("@ss.hasPermi('production:pesticidePurchase:remove')")
    @Log(title = "农药购买信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pesticidePurchaseIds}")
    @ApiOperation("删除农药购买表信息")
    @ApiImplicitParam(name = "pesticidePurchaseIds",value = "农药购买实体类主键数组",paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] pesticidePurchaseIds)
    {
        return toAjax(pesticidePurchaseService.deletePesticidePurchaseByIds(pesticidePurchaseIds));
    }
}
